 # -*- coding: utf-8 -*-
import json

def getConfigList(request):
    request.cursor_standard.execute(request.formatSql('''
        select * 
        from common_field_transfer_config  
		where '${table_code}' = '' 
        or table_code like  '%${table_code}%' 
		order by table_code, is_join_field desc 
    '''))
    rows = request.cursor_standard.fetchall()
    return json.dumps(rows, ensure_ascii=False)


def insertConfig(request):
    request.cursor_standard.execute(request.formatSql('''
        insert into common_field_transfer_config (
            table_code,field_code,target_field_code,
            is_join_field,data_source
        ) values(
            '${table_code}','${field_code}','${target_field_code}',
            '${is_join_field}','${data_source}'
        )
    '''))
    return str(request.cursor_standard.rowcount)

def updateConfig(request):
    request.cursor_standard.execute(request.formatSql('''
        update common_field_transfer_config 
		set table_code = '${table_code}' ,
		field_code = '${field_code}',
		target_field_code = '${target_field_code}',
		is_join_field = '${is_join_field}',
		data_source = '${data_source}'  
		where config_id = ${config_id}
    '''))
    return str(request.cursor_standard.rowcount)

def deleteConfig(request):
    request.cursor_standard.execute(request.formatSql('''
        delete from common_field_transfer_config 
        where config_id = ${config_id}
    '''))
    return str(request.cursor_standard.rowcount)